package com.sh.springbootinit.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sh.springbootinit.model.dto.statistic.AppAnswerCountDTO;
import com.sh.springbootinit.model.dto.statistic.AppAnswerResultCountDTO;
import com.sh.springbootinit.model.entity.UserAnswer;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author 舒云
* @description 针对表【user_answer_0(用户答题记录分表 0)】的数据库操作Mapper
* @createDate 2025-02-01 01:40:58
* @Entity generator.domain.UserAnswer0
*/
public interface UserAnswerMapper extends BaseMapper<UserAnswer> {

    @Select("select " +
            "appId, " +
            "count(userId) as answerCount " +
            "from user_answer " +
            "group by appId " +
            "order by answerCount desc limit 10;")
    List<AppAnswerCountDTO> doAppAnswerCount();


    @Select("select " +
            "resultName, " +
            "count(resultName) as resultCount " +
            "from user_answer " +
            "where appId = #{appId} " +
            "group by resultName " +
            "order by resultCount desc;")
    List<AppAnswerResultCountDTO> doAppAnswerResultCount(Long appId);

}




